package com.wanshi.servlet;

import com.alibaba.fastjson.JSON;
import com.wanshi.entity.Result;
import com.wanshi.exception.UserException;
import com.wanshi.service.OrderService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/order/delOrderById")
public class delOrderById extends HttpServlet {

    private OrderService orderService = new OrderService();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        try{
            //1 获取数据
            String orderid = request.getParameter("id");

            //2 操作数据库
            orderService.delOrderById(orderid);
            //3 输出数据
            response.getWriter().write(JSON.toJSONString(Result.ok()));
        }catch (UserException e){
            response.getWriter().write(JSON.toJSONString(Result.error()));
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}

